﻿<%@ Page Title="" Language="C#" MasterPageFile="~/MasterPages/AdminMaster.master" AutoEventWireup="true" CodeFile="UploadInvoice.aspx.cs" Inherits="UploadInvoice" %>

<%@ Register Assembly="AjaxControlToolkit" Namespace="AjaxControlToolkit" TagPrefix="asp" %>

<asp:Content ID="Content1" ContentPlaceHolderID="head" runat="Server">
</asp:Content>
<asp:Content ID="Content2" ContentPlaceHolderID="ContentPlaceHolder1" runat="Server">
     <style type="text/css">
         .shadow {
            box-shadow: inset 0 0 25px #000000;
            border-radius: 6px;
        }
         </style>
     
    <script>
        function calendarShown(sender, args) {
            sender._popupBehavior._element.style.zIndex = 10005;
        }
    </script>
    <script type="text/javascript" lang="javascript">
        function validateFileSize() {
            var uploadControl = document.getElementById('<%= txtUploadInvoice.ClientID %>');
             var lblSize = document.getElementById('<%= lblMaxFileSize.ClientID %>');
             if (uploadControl.files[0].size > 5342880) {
                 lblSize.innerText = "Uploaded document file size should not be greater than 5 MB.";
                 uploadControl.value = "";
                 return false;
             }
             else {
                 lblSize.innerText = "";
                 return true;
             }
         }

        function Validate(sender, args) {
            var gridView = document.getElementById("<%=gvAInvoice.ClientID %>");
            if (gridView != null) {
                 var checkBoxes = gridView.getElementsByTagName("input");
           
            if (checkBoxes != undefined) {
                for (var i = 0; i < checkBoxes.length; i++) {
                    if (checkBoxes[i].type == "checkbox" && checkBoxes[i].checked) {
                        args.IsValid = true;
                        return;
                    }
                }
                args.IsValid = false;
            }
            else {
                args.IsValid = true;
                return;
            }
            }
        }
        //////////////////////////////////////
        function checkAll(objRef, type) {

            if (type == 'H') {
                var GridView = objRef.parentNode.parentNode.parentNode;
                var inputList = GridView.getElementsByTagName("input");
                for (var i = 0; i < inputList.length; i++) {
                    var row = inputList[i].parentNode.parentNode;
                    if (inputList[i].type == "checkbox" && objRef != inputList[i]) {
                        if (objRef.checked) {
                            inputList[i].checked = true;
                        }
                        else {
                            inputList[i].checked = false;
                        }
                    }
                }
            }
            if (type == 'I') {
                var row = objRef.parentNode.parentNode;
                var GridView = row.parentNode;
                var inputList = GridView.getElementsByTagName("input");

                if (objRef.checked == false) {
                    var CA = $('#ContentPlaceHolder1_gvAInvoice_checkAll');
                    CA[0].checked = false;
                }
            }
            CheckAmount();
        }

        function CheckAmount() {
            var GridView = document.getElementById("<%=gvAInvoice.ClientID %>");
            var inputList = GridView.getElementsByTagName("input");
            var mount = 0.00;
            for (var i = 0; i < inputList.length; i++) {
                var row = inputList[i].parentNode.parentNode;
                if (i > 0) {
                    if (inputList[i].type == "checkbox") {
                        if (inputList[i].checked) {
                            var InvoiceAmount = GridView.rows[i].cells[4].innerText;
                            mount = mount + parseFloat(InvoiceAmount, 10);
                        }
                    }
                }
            }
            var AMT = $('#<%=txtInvoiceAmount.ClientID%>');
            AMT.val(mount.toFixed(2));
        }

        function InvoiceDate(date) {

            var re = /^(0[1-9]|[12][0-9]|3[01])[/](0[1-9]|1[012])[/](19|20)\d\d$/;

            if (date.value != '') {
                $('#<%=lblDtError.ClientID%>').html("");
                if (re.test(date.value)) {
                    $('#<%=lblDtError.ClientID%>').html("");
                    return true;
                }
                else {
                    $('#<%=lblDtError.ClientID%>').html("Date must be mm/dd/yyyy format");
                    return false;
                }
            }
            else {
                $('#<%=lblDtError.ClientID%>').html("");
            }
            //onblur="CheckAmount(this)"
        }
    </script>
    <asp:ScriptManager ID="ScriptID" runat="server"></asp:ScriptManager>
    <table style="width: 100%; margin-left: 0%;" class="shadow" id="TABLE2" cellspacing="1" cellpadding="1" border="0">
        <tbody>
            <tr>
                <td colspan="3" style="text-align: left; padding-left: 4%;">
                    <h2>Upload Invoice</h2>
                </td>
            </tr>
           
            <tr>
                <td align="right" class="auto-style7" style="width:40%;"></td>

                <td style="width: 60%; height: 17px">
                    <asp:Label ID="lblMessage" runat="server" Font-Bold="True"></asp:Label>
                </td>
            </tr>
            <tr>
                <td colspan="2">
                    <div class="grd_table" style="max-height: 150px;overflow-y: scroll; margin-left:3%; width:94%;" runat="server" >
                        <asp:GridView ID="gvAInvoice" runat="server" Width="100%" AutoGenerateColumns="false" OnRowDataBound="gvAInvoice_RowDataBound"
                            AllowPaging="false" OnRowDeleting="gvAInvoice_RowDeleting" OnSelectedIndexChanged="gvAInvoice_SelectedIndexChanged"
                            DataKeyNames="InvoiceID" PageSize="6">
                            <Columns>
                                <asp:BoundField DataField="InvoiceNo" HeaderText="Invoice No.">
                                    <ItemStyle Width="30%" HorizontalAlign="Left" />
                                    <HeaderStyle HorizontalAlign="Left" />
                                </asp:BoundField>
                                <asp:BoundField DataField="InvoiceDate" HeaderText="Invoice Date">
                                    <ItemStyle Width="30%" HorizontalAlign="Left" />
                                    <HeaderStyle HorizontalAlign="Left" />
                                </asp:BoundField>
                                <asp:BoundField DataField="InvoiceAmount" HeaderText="Invoice Amount">
                                    <ItemStyle Width="30%" HorizontalAlign="Left" />
                                    <HeaderStyle HorizontalAlign="Left" />
                                </asp:BoundField>
                                <asp:BoundField DataField="InvoiceComment" HeaderText="Invoice Comment">
                                    <ItemStyle Width="30%" HorizontalAlign="Left" />
                                    <HeaderStyle HorizontalAlign="Left" />
                                </asp:BoundField>
                            </Columns>
                        </asp:GridView>
                    </div>
                </td>
            </tr>
              <tr>
                <td align="right" colspan="2" style="height: 10px; text-align: center">&nbsp;</td>
            </tr>
            <tr>
                <td align="right" class="auto-style10" style="width:40%;">Invoice No&nbsp;<font color="red">*</font> &nbsp;&nbsp;&nbsp;:&nbsp;&nbsp;</td>

                <td class="auto-style9" style="width:60%;">
                    <asp:TextBox ID="txtInvoiceNo" runat="server" Width="220px"></asp:TextBox>
                    &nbsp;<asp:RequiredFieldValidator Display="Dynamic" ID="reqLanguageName" ControlToValidate="txtInvoiceNo" runat="server" ForeColor="Red" ErrorMessage="Enter Invoice No."></asp:RequiredFieldValidator>
                     <asp:RegularExpressionValidator ID="regLanguageAllowd" runat="server" ErrorMessage="Do not use special characters" 
                                                                         Display="Dynamic" ControlToValidate="txtInvoiceNo" ForeColor="Red" ValidationExpression="^[a-zA-Z0-9\-_\s]*$" />
                </td>
            </tr>
            <tr>
                <td align="right" colspan="2" style="height: 10px; text-align: center">&nbsp;</td>
            </tr>
            <tr>
                <td align="right" class="auto-style10">Invoice Date&nbsp;<font color="red">*</font>&nbsp;&nbsp;:&nbsp;&nbsp;</td>

                <td class="auto-style9">
                    <div class="controls input-append date form_date" data-date="" data-date-format="dd MM yyyy" data-link-field="dtp_input1" data-link-format="yyyy-mm-dd">
                        <asp:TextBox ID="txtInvoiceDate" runat="server" MaxLength="50" placeholder="Enter Invoice Date" ViewStateMode="Enabled" Width="100px"
                            cultureinvariantvalues="true" onblur="InvoiceDate(this)"></asp:TextBox>

                        <asp:CalendarExtender ID="mdlStartDate" runat="server" Format="dd/MM/yyyy" PopupButtonID="popcalender1" OnClientShown="calendarShown" TargetControlID="txtInvoiceDate" />
                        <i class="icon-th" id="popcalender1"></i>
                        <asp:RequiredFieldValidator runat="server" ID="rfvDate" ControlToValidate="txtInvoiceDate" Display="Dynamic"
                            ErrorMessage="Select Invoice Date" ForeColor="Red"></asp:RequiredFieldValidator>
                        <asp:Label runat="server" ID="lblDtError" Text=" " ForeColor="Red" Visible="true"></asp:Label>
                    </div>
                </td>
            </tr>
            <tr>
                <td align="right" colspan="2" style="height: 10px; text-align: center">&nbsp;</td>
            </tr>
            <tr>
                <td align="right" class="auto-style10">Invoice Amount&nbsp;<font color="red">*</font>&nbsp;&nbsp;:&nbsp;&nbsp;</td>

                <td class="auto-style9"">
                    <asp:TextBox ID="txtInvoiceAmount" style="text-align: right" runat="server" Width="100px"></asp:TextBox>
                    &nbsp;&nbsp;(GBP)<asp:RequiredFieldValidator Display="Dynamic" ID="reqLanguageName1" runat="server" ControlToValidate="txtInvoiceAmount" ForeColor="Red" ErrorMessage="Enter Invoice Amount."></asp:RequiredFieldValidator><asp:RegularExpressionValidator ID="regExpVal" runat="server" Display="Dynamic" ForeColor="Red" ValidationExpression="((\d+)((\.\d{1,2})?))$" ErrorMessage="Please enter valid integer or decimal number with 2 decimal places." ControlToValidate="txtInvoiceAmount" />
                </td>
            </tr>
            <tr>
                <td align="right" colspan="2" style="height: 10px; text-align: center">&nbsp;</td>
            </tr>
            <tr>
                <td align="right" style="vertical-align: text-top; padding-top: 10px;" class="auto-style10">Upload Invoice&nbsp;<font color="red">*</font>&nbsp;&nbsp;:&nbsp;&nbsp;</td>

                <td class="auto-style9">
                    <asp:FileUpload ID="txtUploadInvoice" Width="220px" runat="server" onchange="validateFileSize();" />
                    &nbsp;<asp:RequiredFieldValidator ID="reqLanguageName2" runat="server" ControlToValidate="txtUploadInvoice"
                        ErrorMessage="Select Upload Invoice File." Display="Dynamic" ForeColor="Red"></asp:RequiredFieldValidator>
                    <asp:Label runat="server" ID="lblMaxFileSize" Text="" ForeColor="Red" ></asp:Label>
                    &nbsp;<asp:HiddenField runat="server" ID="hdnUploadDoc" />
                    <asp:Label ID="LalblUploadInvoice" runat="server" Text=""></asp:Label>
                </td>
            </tr>
            <tr>
                <td align="right" colspan="2" style="height: 10px; text-align: center">&nbsp;</td>
            </tr>
            <tr>
                <td align="right" class="auto-style10" style="vertical-align: central;">Invoice Comments&nbsp;<font color="red">*</font>&nbsp;&nbsp;:&nbsp;&nbsp; </td>

                <td class="auto-style9">
                    <asp:TextBox ID="txtInvoiceComments" TextMode="MultiLine" runat="server" Width="220px" MaxLength="50"></asp:TextBox>
                    &nbsp;<asp:RequiredFieldValidator ID="RequiredFieldValidator1" ForeColor="Red" runat="server" ControlToValidate="txtInvoiceComments"
                        ErrorMessage="Enter Invoice Comments." Display="Dynamic"></asp:RequiredFieldValidator>


                </td>
            </tr>
            <tr>
                <td align="right" class="auto-style11"></td>

                <td style="width: 54%; height: 18px"></td>
            </tr>


            <tr>
                <td align="right" colspan="2" style="height: 30px; text-align: center"></td>
            </tr>
            <tr>
                <td align="right" colspan="2" style="height: 30px; text-align: center;">

                    <asp:Button ID="btnSave" runat="server" SkinID="buttonSkin" Text="Save" OnClick="btnSave_Click" />
                    &nbsp; &nbsp;
                                <asp:Button ID="btnCancel" runat="server" CausesValidation="false" OnClick="btnCancel_OnClick" SkinID="buttonSkin" Text="Cancel" />
                    <%-- <asp:Button ID="btnCancel" runat="server" CausesValidation="false" OnClick="btnCancel_OnClick" SkinID="buttonSkin" Text="Cancel" />--%>
                </td>
            </tr>
            <tr>
                <td align="right" colspan="2" style="height: 30px; text-align: center"></td>
            </tr>

        </tbody>
    </table>

</asp:Content>

